package com.film.admincontroller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Performer;
import com.film.service.PerformerService;
import com.film.service.impl.PerformerServiceImpl;

/**
 * 该控制类用来做分类查询
 * @author 2119196781
 *
 */
@WebServlet("/adminPerformerServlet.do")
public class PerformerAdminController extends HttpServlet{
	PerformerService  performerService = new PerformerServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		System.out.println(req.getParameter("PerformerIf"));
//		if("addPerformer".equals(req.getParameter("PerformerIf"))){
//			addPerformer(req,resp);
//		}
		if("updatePerformer".equals(req.getParameter("PerformerIf"))){
			updatePerformer(req,resp);
		}
		if("deletePerformer".equals(req.getParameter("PerformerIf"))) {
			deletePerformer(req,resp);
		}
		if("PerformerDtail".equals(req.getParameter("PerformerIf"))){
			PerformerDtail(req,resp);
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
//	//添加
//	public void addPerformer(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
//		String perName = req.getParameter("perName");
//		String perNickName = req.getParameter("perNickName");
//		String perTypr = req.getParameter("perTypr");
//		String perBirth = req.getParameter("perBirth");
//		String perHeight = req.getParameter("perHeight");
//		String perSex = req.getParameter("perSex");
//		String perNationnality = req.getParameter("perNationnality");
//		String perBirthPlace = req.getParameter("perBirthPlace");
//		String perStar = req.getParameter("perStar");
//		String perIntroduce = req.getParameter("perIntroduce");
//		String perImg = req.getParameter("perImg");
//	
//		Performer performer = new Performer(perName,perNickName,perTypr,perBirth,perHeight,perSex,perNationnality,perBirthPlace,perStar,perIntroduce,perImg);
//		performerService.addPerformer(performer);
//		resp.sendRedirect("/film/adminPerformer.do");
//	}
	//修改
	public void updatePerformer(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		Integer perId = Integer.parseInt(req.getParameter("perId"));
		String perName = req.getParameter("perName");
		String perNickName = req.getParameter("perNickName");
		String perTypr = req.getParameter("perTypr");
		String perBirth = req.getParameter("perBirth");
		String perHeight = req.getParameter("perHeight");
		String perSex = req.getParameter("perSex");
		String perNationnality = req.getParameter("perNationnality");
		String perBirthPlace = req.getParameter("perBirthPlace");
		String perStar = req.getParameter("perStar");
		String perIntroduce = req.getParameter("perIntroduce");
		String perImg = req.getParameter("perImg");
		Performer performer = new Performer(perId,perName,perNickName,perTypr,perBirth,perHeight,perSex,perNationnality,perBirthPlace,perStar,perIntroduce,perImg);
		performerService.updatePerformer(performer);
		resp.sendRedirect("/film/adminPerformer.do");
	}
	//删除
	public void deletePerformer(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Integer perId = Integer.parseInt(req.getParameter("perId"));
		performerService.deletePerformer(perId);
	}
	//明细
	public void PerformerDtail(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		int perId = Integer.parseInt(req.getParameter("perId"));
		PerformerService performerservice = new PerformerServiceImpl();
		List<Performer> list = performerservice.selectPerformer(perId);
		Performer performerDtail = list.get(0);
		HttpSession session = req.getSession();
		session.setAttribute("performerDtail", performerDtail);
	}
}
